2.C++基本数据类型、类型修饰符、变量和常量、#define宏和const关键字 |
您所在的位置:网站首页 › c 定义变量 类型有哪些 › 2.C++基本数据类型、类型修饰符、变量和常量、#define宏和const关键字 |
基本数据类型
七种基本的 C++ 数据类型: signed unsigned short long 一些基本类型可以使用一个或多个类型修饰符进行修饰。C++允许在Char int double 前放置类型修饰符。 修饰符 signed、unsigned、long 和 short 可应用于整型,signed 和 unsigned 可应用于字符型,long 可应用于双精度型。修饰符 signed 和 unsigned 也可以作为 long 或 short 修饰符的前缀。例如:unsigned long int。 省略int:C++ 允许使用速记符号来声明无符号短整数或无符号长整数。您可以不写 int,只写单词 unsigned、short 或 unsigned、long,int 是隐含的。例如,下面的两个语句都声明了无符号整型变量。 unsigned x; unsigned int y;
下面着重探讨一下类型修饰符的符号:
为了理解 C++ 解释有符号整数和无符号整数修饰符之间的差别,我们来运行一下下面这个短程序: #include using namespace std; /* * 这个程序演示了有符号整数和无符号整数之间的差别 */ int main() { short int i; // 有符号短整数 short unsigned int j; // 无符号短整数 j = 50000; i = j; cout |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |